#include <typedefs.h>
#include <process.h>
#include <windows.h>
#include <blower.h>
#include <main.h>

static HANDLE mainThreadHandle = NULL;

static void main_local(void* dummy)
{
	__try {     
		blower_run();
	}
	//__except () 
	__except (1)
	{
		// handle exit here..
	}

	mainThreadHandle = NULL;
}

__declspec(dllexport) void main_kill(void)
{
	if (mainThreadHandle != NULL)
	{
		TerminateThread(mainThreadHandle, 0);
	}
}

/// <summary>
/// External main entry point
/// </summary>
__declspec(dllexport) void main(void)
{
	if (mainThreadHandle != 0) {
        main_kill();
    }

    mainThreadHandle = (HANDLE)_beginthread(main_local, 0, NULL);
}
